//
//  DLCircleListCollectionViewCell.m
//  FRP_OC
//
//  Created by DeLongYang on 2017/11/3.
//  Copyright © 2017年 DeLongYang. All rights reserved.
/*
    !!!   笔者认为这更像是 MVC 中MV 的刷新方式 
 */

#import "DLCircleListCollectionViewCell.h"

@interface DLCircleListCollectionViewCell ()

@property (nonatomic,strong) UIImageView *headerImageView;

@property (nonatomic,strong) UILabel *nameLable;

@end

@implementation DLCircleListCollectionViewCell

#pragma mark ----  lazy load
- (UIImageView *)headerImageView
{
    if (!_headerImageView) {
        _headerImageView = [[UIImageView alloc] init];
    }
    return  _headerImageView;
}

- (UILabel *)nameLable
{
    if (!_nameLable) {
        _nameLable = [[UILabel alloc]init];
        _nameLable.font = SYSTEMFONT(12);
        _nameLable.textColor = MAIN_LINE_COLOR;
        _nameLable.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLable;
}

#pragma mark ---- DLView Protocol
- (void)dl_setupViews
{
    [self.contentView addSubview:self.headerImageView];
    [self.contentView addSubview:self.nameLable];
    
    [self setNeedsUpdateConstraints];
    [self updateConstraintsIfNeeded];
}

- (void)updateConstraints
{
    WS(weakSelf)
    CGFloat paddingEdge = 10;
    [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(weakSelf.contentView);
        make.height.equalTo(@80);
    }];
    
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.headerImageView.mas_bottom).offset(paddingEdge);
        make.left.right.equalTo(weakSelf.headerImageView);
        make.height.equalTo(@15);
    }];
    
    [super updateConstraints];
}

#pragma mark ---- setter
- (void)setType:(NSString *)type
{
    self.headerImageView.image = ImageNamed(@"header");
    self.nameLable.text = @"加入新圈子";
}

- (void)setViewModel:(DLCircleListCollectionCellViewModel *)viewModel
{
    if (!viewModel) {
        return;
    }
    
    _viewModel = viewModel;
    
    [self.headerImageView sd_setImageWithURL:URL(viewModel.headerImageStr) placeholderImage:ImageNamed(@"yc_circle_placeHolder.png")];
    self.nameLable.text = viewModel.name;
    
}
























@end
